<?php

namespace app\admin\controller;
use app\admin\model\shopro\user\View;
use think\db;
use app\common\controller\Backend;
use base\Wx;

class SelfRe extends Backend
{
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
    }

    public function import()
    {
        parent::import();
    }

 
    public function wxRefund() {
        //die;
        $config = [
            'app_id'    => 'wx00e9e5b843259a9d',
            'mch_id'    => '1584376091',
            'key'       => 'TjRUCktaUcR6RQqCksBtwKRY8KwSTC4M',
            'secret'    => 'cce6015196dbba888133f9a3613b18b7',
            'notify'    => 'http://bao.scwushen.com/index.php/api/notify/SelfRe',
        ];

        $obj = new Wx( $config );
        
        $orders = array(            
    array('m'=>'1','o'=>'BYD_20220425100307697941')


            );
        foreach ($orders as $v)
        {
            $orderInfo = $v['o'];
            if($orderInfo == '') die('fail');
            else {
                
                $data = [
                    'out_trade_no'  => $orderInfo ,
                    'out_refund_no' => $orderInfo . 'tu1i',
                    'total_fee'     => $v['m'] * 100,
                    'refund_fee'    => $v['m'] * 100,
                ];
        
                $sslCert = substr($_SERVER['DOCUMENT_ROOT'],0,-6) .'/byd-wx-rsakey/bydwxssl_cert.pem';
                $sslKey = substr($_SERVER['DOCUMENT_ROOT'],0,-6) .'/byd-wx-rsakey/bydwxssl_key.pem';
        
                $ret = $obj->refund( $data, $sslCert, $sslKey );
                echo "<br />------------------------<br />";
                print_r($ret); 
                sleep(1);
            }
        }
       die;
    }
}
